const dbpool = require('../config/dbpoolconfig');

const webcastController = {
    // 直播列表
    webcastList(req, res) {
        dbpool.connect('select * from webcastlist', [], (err, data) => {
            if (!err) {
                res.send(data);
            }
        })
    },
    // 搜索
    webcastListSearch(req, res) {
        let name = req.query.name || '';


        let sql = 'select * from webcastlist where 1=1 ';
        let params = [];

        if (name.trim() != '') {
            sql += 'and name like ?';
            name = '%' + name.trim() + '%';
            params.push(name)
        }


        dbpool.connect(sql, params, (err, data) => {
            if (!err) {
                res.send(data);
            }
        })

    },
    // 禁播
    banWebcast(req,res){
        let id = req.query.id || req.body.id;
        let mode = req.query.mode || '';
        let operate = req.query.operate || '';

        if(mode == '直播中'){
            mode = '已禁播'
            operate = '解除'
        }else{
            mode = '直播中'
            operate = '禁播'
        }

        
        dbpool.connect('update webcastlist set mode = ?,operate = ? where id = ?',[mode,operate,id],(err,data)=>{
            
            if(!err){
                res.send('success')
            }
        })
    }
}

module.exports = webcastController;